﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour {
    public float moveSpeed = 8;
    public float rotateSpeed = 50;
    GameObject effectPre;
	// Use this for initialization
	void Start () {
        effectPre = Resources.Load<GameObject>("explosion_asteroid");
        //三秒后自动销毁陨石
        Destroy(this.gameObject, 3f);
	}
	
	// Update is called once per frame
	void Update () {
        Move();
        Rotate();
	}
    //移动的方法
    void Move()
    {
        transform.position = transform.position + new Vector3(0, 0, -1) * moveSpeed * Time.deltaTime;
    }
    //旋转的方法
    void Rotate()
    {
        transform.Rotate (new Vector3(1,1,1) * rotateSpeed * Time.deltaTime);
    }

    //如果陨石撞到子弹
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "PlayerBullet" )
        {
            Destroy(this.gameObject );//销毁陨石
            Destroy(other.gameObject);//销毁子弹
            Instantiate(effectPre, this.transform.position, Quaternion.identity);
        }

    }
}
